<?php

require_once dirname(__FILE__).'/../lib/projectGeneratorConfiguration.class.php';
require_once dirname(__FILE__).'/../lib/projectGeneratorHelper.class.php';

/**
 * project actions.
 *
 * @package    sf_sandbox
 * @subpackage project
 * @author     Your name here
 * @version    SVN: $Id: actions.class.php 12474 2008-10-31 10:41:27Z fabien $
 */
class projectActions extends autoProjectActions
{
	public function executeShow(sfWebRequest $request)
	{
    $this->forward404Unless($this->project = Doctrine::getTable('Project')->find(array($request->getParameter('id'))), sprintf('Object project does not exist (%s).', array($request->getParameter('id'))));
	}
  protected function processForm(sfWebRequest $request, sfForm $form)
  {
    $form->bind($request->getParameter($form->getName()), $request->getFiles($form->getName()));
    if ($form->isValid())
    {
      $this->getUser()->setFlash('notice', $form->getObject()->isNew() ? 'The item was created successfully.' : 'The item was updated successfully.');

      $project = $form->save();
      $project->calcStatus();

      $this->dispatcher->notify(new sfEvent($this, 'admin.save_object', array('object' => $project)));

      if ($request->hasParameter('_save_and_add'))
      {
        $this->getUser()->setFlash('notice', $this->getUser()->getFlash('notice').' You can add another one below.');

        $this->redirect('@project_new');
      }
      else
      {
        $this->redirect('@project_show?id='.$project['id']);
      }
    }
    else
    {
      $this->getUser()->setFlash('error', 'The item has not been saved due to some errors.');
    }
  }
  public function executeDeletecontract(sfWebRequest $request)
  {
    $request->checkCSRFProtection();

    $this->dispatcher->notify(new sfEvent($this, 'admin.delete_object', array('object' => $this->getRoute()->getObject())));

    $contract=$this->getRoute()->getObject();
    //$project=$contract->getProject();
    //$recalc=false;
    //if($project->getLatestcontract()->getId()==$contract->getId())$recalc=true;
    $contract->delete();
    //if($recalc)$project->recalcStepIncrements();

    $this->getUser()->setFlash('notice', 'The item was deleted successfully.');

    $this->redirect($this->request->getReferer());
  }
}
